package cn.mapway.ib.share.model.common;

import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class ApiResult<T> {
    public int code;
    public String message;
    public T data;

    @JsOverlay
    public final static ApiResult ok(Object data) {
        ApiResult result = new ApiResult();
        result.code = ResultCode.OK;
        result.message = "";
        result.data = data;
        return result;
    }

    @JsOverlay
    public final static ApiResult fail(String message) {
        ApiResult result = new ApiResult();
        result.code = ResultCode.FAILED;
        result.message = message;
        result.data = null;
        return result;
    }

    @JsOverlay
    public final boolean isSuccess() {
        return code == ResultCode.OK;
    }
}
